package com.cskaoyan.order.biz.handler;

import com.cskaoyan.order.biz.context.CreateOrderContext;
import com.cskaoyan.order.biz.context.TransHandlerContext;
import com.cskaoyan.order.mq.producer.DelyOrderCancelProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 利用mq发送延迟取消订单消息
 **/
@Component
@Slf4j
public class SendMessageHandler extends AbstractTransHandler {


	@Autowired
	DelyOrderCancelProducer producer;

	@Override
	public boolean isAsync() {
		return false;
	}

	@Override
	public boolean handle(TransHandlerContext context) {
		//代码执行至此，说明下单已成功
		CreateOrderContext createOrderContext = (CreateOrderContext) context;
		//已经下单成功的代码，发送延迟消息即可
		String orderId = createOrderContext.getOrderId();
		//将orderId放入延迟消息中发送(调用我们自己定义的producer对象)

		// 调用一个方法实现延迟消息的发送
		return producer.sendOrderCancelMessage(orderId);
	}
}